'use strict'

const log4js = require('koa-log4')
const logger = log4js.getLogger('app')
const URLConfig = require('../config/config')
const RequestUtil = require('../utils/requestUtil') 
const StatisticsService = require('../service/statistics.service') 
const fs=require('fs'); 
const path = require('path')

exports.forecast = async (ctx, next) => {
  // logger.info("path:"+path.join(__dirname, "../json/forecast.json"));
	// var responseData=JSON.parse(fs.readFileSync(path.join(__dirname, "../json/forecast.json")));
	// ctx.response.body = responseData;  
	var url = URLConfig.url.rms.forecastList
	var content = ctx.request.body;
	logger.info("forecast查询req："+url+",请求JSON："+JSON.stringify(content));
	var responseData = await RequestUtil.POST(ctx,url,content); // 这里调用要在 async 函数里
	logger.info("forecast查询res："+JSON.stringify(responseData))
	ctx.response.body = responseData;  
}

 
exports.optimization = async (ctx, next) => {
  // logger.info("path:"+path.join(__dirname, "../json/optimization.json"));
	// var responseData=JSON.parse(fs.readFileSync(path.join(__dirname, "../json/optimization.json")));
	// ctx.response.body = responseData;  
	var url = URLConfig.url.rms.optimizationList
	var content = ctx.request.body;
	logger.info("optimization查询req："+url+",请求JSON："+JSON.stringify(content));
	var responseData = await RequestUtil.POST(ctx,url,content); // 这里调用要在 async 函数里
	logger.info("optimization查询res："+JSON.stringify(responseData))
	ctx.response.body = responseData; 
}

exports.schedule = async (ctx, next) => {
  // logger.info("path:"+path.join(__dirname, "../json/schedule.json"));
	// var responseData=JSON.parse(fs.readFileSync(path.join(__dirname, "../json/schedule.json")));
	// ctx.response.body = responseData;  
	var url = URLConfig.url.rms.scheduleList
	var content = ctx.request.body;
	logger.info("schedule查询req："+url+",请求JSON："+JSON.stringify(content));
	var responseData = await RequestUtil.POST(ctx,url,content); // 这里调用要在 async 函数里
	logger.info("schedule查询res："+JSON.stringify(responseData))
	ctx.response.body = responseData;  
}

exports.class = async (ctx, next) => {
	var url = URLConfig.url.rms.classList
	var content = ctx.request.body;
	logger.info("class查询req："+url+",请求JSON："+JSON.stringify(content));
	var responseData = await RequestUtil.POST(ctx,url,content); // 这里调用要在 async 函数里
	logger.info("class查询res："+JSON.stringify(responseData))
	ctx.response.body = responseData;  
  // logger.info("path:"+path.join(__dirname, "../json/class.json"));
	// var responseData=JSON.parse(fs.readFileSync(path.join(__dirname, "../json/class.json")));
	// var classList = ['F','C','W','Y'];
	// 	for(var j = 0 ;j<responseData.cabinSequence.length;j++){  
	// 		var cabinList = [];
	// 			for(var i = 0 ;i<classList.length;i++){
	// 				var newjson = {"cabinCode":classList[i],"cabinDetail":[]};
	// 				for(var m = 0 ;m<responseData.cabinSequence[j].detail.length;m++){
	// 						var cabinCode = responseData.cabinSequence[j].detail[m].cabinCode;
	// 						if(cabinCode == classList[i]){
	// 							newjson.cabinCode=cabinCode;
	// 							newjson.cabinDetail.push(responseData.cabinSequence[j].detail[m]);
	// 							// logger.info("cabinDetail:"+JSON.stringify(responseData.cabinSequence[j].detail[m]))
	// 							logger.info("cabinList:"+JSON.stringify(newjson));
	// 						} 
	// 				} 
	// 				cabinList.push(newjson);
	// 				responseData.cabinSequence[j].cabinList=cabinList;
	// 			}
			
	// 	}

	// ctx.response.body = responseData;  
}

exports.statistics = async (ctx, next) => {
  // logger.info("path:"+path.join(__dirname, "../json/ss.json"));
	// // var responseData=JSON.parse(fs.readFileSync(path.join(__dirname, "../json/ss.json")));
	// var param = {
	// 	"size":100000,
	// 	"height":180,
	// 	"error":20
	// }
	// var responseData= StatisticsService.createRadomData(param);
	// logger.info("responseData:"+responseData)
	var url = URLConfig.url.python.simulation
	var content = ctx.request.body;
	logger.info("class查询req："+url+",请求JSON："+JSON.stringify(content));
	var responseData = await RequestUtil.POST(ctx,url,content); // 这里调用要在 async 函数里
	// logger.info("class查询res："+JSON.stringify(responseData))
	ctx.response.body = responseData;
}
